package com.ruoyi.project.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.product.domain.InsMachineBoxBarcodeTag;
import com.ruoyi.project.product.service.IInsMachineBoxBarcodeTagService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 盒贴标签模板Controller
 *
 * @author taney
 * @date 2021-01-05
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product/machineBoxBarcodeTag" )
public class InsMachineBoxBarcodeTagController extends BaseController {

    private final IInsMachineBoxBarcodeTagService iInsMachineBoxBarcodeTagService;

    /**
     * 查询盒贴标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsMachineBoxBarcodeTag insMachineBoxBarcodeTag)
    {
        startPage();
        LambdaQueryWrapper<InsMachineBoxBarcodeTag> lqw = new LambdaQueryWrapper<InsMachineBoxBarcodeTag>();
        if (StringUtils.isNotBlank(insMachineBoxBarcodeTag.getMachineType())){
            lqw.eq(InsMachineBoxBarcodeTag::getMachineType ,insMachineBoxBarcodeTag.getMachineType());
        }
        if (StringUtils.isNotBlank(insMachineBoxBarcodeTag.getTempName())){
            lqw.like(InsMachineBoxBarcodeTag::getTempName ,insMachineBoxBarcodeTag.getTempName());
        }
        if (insMachineBoxBarcodeTag.getTempCodeno() != null){
            lqw.eq(InsMachineBoxBarcodeTag::getTempCodeno ,insMachineBoxBarcodeTag.getTempCodeno());
        }
        List<InsMachineBoxBarcodeTag> list = iInsMachineBoxBarcodeTagService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出盒贴标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:export')" )
    @Log(title = "盒贴标签模板" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsMachineBoxBarcodeTag insMachineBoxBarcodeTag) {
        LambdaQueryWrapper<InsMachineBoxBarcodeTag> lqw = new LambdaQueryWrapper<InsMachineBoxBarcodeTag>(insMachineBoxBarcodeTag);
        List<InsMachineBoxBarcodeTag> list = iInsMachineBoxBarcodeTagService.list(lqw);
        ExcelUtil<InsMachineBoxBarcodeTag> util = new ExcelUtil<InsMachineBoxBarcodeTag>(InsMachineBoxBarcodeTag. class);
        return util.exportExcel(list, "machineBoxBarcodeTag" );
    }

    /**
     * 获取盒贴标签模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:query')" )
    @GetMapping(value = "/{boxBarcodeTagTempId}" )
    public AjaxResult getInfo(@PathVariable("boxBarcodeTagTempId" ) Integer boxBarcodeTagTempId) {
        return AjaxResult.success(iInsMachineBoxBarcodeTagService.getById(boxBarcodeTagTempId));
    }

    /**
     * 新增盒贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:add')" )
    @Log(title = "盒贴标签模板" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsMachineBoxBarcodeTag insMachineBoxBarcodeTag) {
        return toAjax(iInsMachineBoxBarcodeTagService.save(insMachineBoxBarcodeTag) ? 1 : 0);
    }

    /**
     * 修改盒贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:edit')" )
    @Log(title = "盒贴标签模板" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsMachineBoxBarcodeTag insMachineBoxBarcodeTag) {
        return toAjax(iInsMachineBoxBarcodeTagService.updateById(insMachineBoxBarcodeTag) ? 1 : 0);
    }

    /**
     * 删除盒贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBoxBarcodeTag:remove')" )
    @Log(title = "盒贴标签模板" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{boxBarcodeTagTempIds}" )
    public AjaxResult remove(@PathVariable Integer[] boxBarcodeTagTempIds) {
        return toAjax(iInsMachineBoxBarcodeTagService.removeByIds(Arrays.asList(boxBarcodeTagTempIds)) ? 1 : 0);
    }
}
